package _0entity;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * @ClassName Result
 * @Description: 请求结果集
 * @Author wangzhen
 * @Date 2020/2/7
 **/
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 2518327762097384157L;

    /** 请求状态码 */
    private int code=200;

    /** 请求状态 */
    private boolean status=true;

    /** 提示信息 */
    private String message;

    /** 数据 */
    private T data;

    /** 生成时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")//返回页面时的时间戳改为ymd格式,并且时区+8
    private Date time=new Date();


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }



    public Result<T> setSuccess(String message, T data){
        this.message=message;
        this.data=data;

        return this;
    }



    public Result<T> setError(String message,T data){
        this.code=500;
        this.status=false;
        this.message=message;
        this.data=data;

        return this;
    }



    public static <T> Result<T> ok(String message,T data){
        Result<T> result=new Result();
        result.setMessage(message);
        result.setData(data);

        return result;
    }



    public static <T> Result<T> error500(String message,T data){
        Result<T> result=new Result();
        result.setCode(500);
        result.setStatus(false);
        result.setMessage(message);
        result.setData(data);

        return result;
    }
}
